package com.ndphu.comic.gui.pager.animation;

import android.support.v4.view.ViewPager;
import android.view.View;

public class FlipPageTransformer implements ViewPager.PageTransformer {

	public void transformPage(View view, float position) {
		int pageWidth = view.getWidth();
		int pageHeight = view.getHeight();

		if (position < -1) { // [-Infinity,-1)
			view.setAlpha(1);
		} else if (position <= 1) { // [-1,1]
			if (position < 0) {
				int trans = (int)(-position * pageWidth);
				if (Math.abs(trans) < 2) {
					trans = 0;
				}
				view.setTranslationX(trans);
				view.setPivotX(0);
				view.setPivotY(pageHeight / 2);
				view.setRotationY(position * 90);
				view.setAlpha((1 + position) * 2);
				view.setScaleX(1 + position);
			} else if (position > 0) {
				int trans = (int)(-position * pageWidth);
				if (Math.abs(trans) < 2) {
					trans = 0;
				}
				view.setTranslationX(trans);
			}

		} else { // (1,+Infinity]
			view.setAlpha(1);
		}
	}
}